<template>
  <span
    v-loading="loading"
    element-loading-spinner="el-icon-loading"
    class="dsc-download"
    @click="download">
    <slot />
  </span>
</template>
<script>
import { downloadFile } from '@/utils/public'
export default {
  name: 'Download',
  props: {
    params: {
      type: Object,
      required: true,
      default() {
        return {
          url: '', // 下载路径
          fileName: '' // 文件名
        }
      }
    }
  },
  data() {
    return {
      loading: false
    }
  },
  methods: {
    download() {
      this.loading = true
      downloadFile(this.params).then(response => {
        this.loading = false
      }).catch(_ => {
        this.loading = false
      })
    }
  }
}
</script>
<style>
.dsc-download .el-loading-spinner{
  top: 0;
  margin: 0;
  line-height: initial;
}
</style>
